//
//  CustomClickableView.swift
//  LeTu
//
//  Created by gy on 2023/11/30.
//

import UIKit

class CustomClickableView: UIView {

    var isEnabled: Bool {
        get {
            return self.isUserInteractionEnabled
        }
        set {
            self.isUserInteractionEnabled = newValue
        }
    }
    
    init() {
        super.init(frame: .zero)
        
        configUI()
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    func imagePosition(style: RGButtonImagePosition, spacing: CGFloat) {
        contentBtn.imagePosition(style: style, spacing: spacing)
    }
    
    /// 设置标题颜色
    func setTitleColor(_ color: UIColor) {
        contentBtn.setTitleColor(color, for: .disabled)
        contentBtn.setTitleColor(color, for: .normal)
    }
    
    /// 设置字体大小
    func setFont(_ font: UIFont) {
        contentBtn.titleLabel?.font = font
    }
    
    /// 设置标题
    func setTitle(_ title: String) {
        contentBtn.setTitle(title, for: .disabled)
        contentBtn.setTitle(title, for: .normal)
    }
    
    /// 设置图片
    func setImage(_ image: UIImage?) {
        contentBtn.setImage(image, for: .disabled) 
        contentBtn.setImage(image, for: .normal)
    }
    
    /// 设置背景图片
    func setBackgroundImage(_ image: UIImage?) {
        contentBtn.setBackgroundImage(image, for: .disabled)
        contentBtn.setBackgroundImage(image, for: .normal)
    }
    
    /// 设置图片间距
    func setImageEdgeInsets(_ insets: UIEdgeInsets) {
        contentBtn.imageEdgeInsets = insets
    }
    
    /// 设置title间距
    func setTitleEdgeInsets(_ insets: UIEdgeInsets) {
        contentBtn.titleEdgeInsets = insets
    }
    
    /// 添加手势
    func addTarget(_ target: Any?, action: Selector) {
        
        let tapGesture = UITapGestureRecognizer(target: target, action: action)
        self.addGestureRecognizer(tapGesture)
        
    }
    
    // MARK: - configUI
    func configUI() {
        
        addSubview(contentBtn)
        
        contentBtn.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

    }
    private(set) lazy var contentBtn: UIButton = {
        let contentBtn = UIButton()
        contentBtn.isEnabled = false
        return contentBtn
    }()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
